package com.zynn.recommend.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.zynn.recommend.bean.Menu;
import com.zynn.recommend.bean.ShowNotice;
import com.zynn.recommend.config.properties.LinProperties;
import com.zynn.recommend.service.MenuService;
import com.zynn.recommend.service.NoticeService;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


/**
 * @author jerry-liqi
 *
 * 登录首页信息
 */
@Controller
public class HomeController {

	private Logger log = LoggerFactory.getLogger(this.getClass());

///	@Autowired
//	private LinProperties linProperties;
//	@Autowired
//	private NoticeService noticeService;
//	@Autowired
//	private MenuService menuService;
	
	@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.POST })
	public String home(HttpServletRequest request) {
		log.info("home page");
///		if (!SecurityUtils.getSubject().isAuthenticated() || Userinfo.getUser() == null) {
//			request.setAttribute("kaptcha", linProperties.isKptchaswich());
//			return "login2";
//		}
		
		/** 查询通知 */
		/// List<ShowNotice> list = noticeService.getAllShowNotice();
		List<ShowNotice> list = new ArrayList<>();
		ShowNotice showNotice  = new ShowNotice();
		showNotice.setBody("欢迎使用忆年推荐系统(●'◡'●) ");
		showNotice.setSendUsername("admin");
		showNotice.setMessage("欢迎光临");
		showNotice.setCreatetime("2018-11-23 11:52:23");
		request.setAttribute("noticelist", list);
		
		/// List<Menu> menuList = menuService.getUserMenu();

		List<Menu> menuList = new ArrayList<>();
		Menu menu = new Menu();

		// 1			用户管理	fa-columns	/userpage		1
		menu.setName("用户统计");
		menu.setIcon("fa-columns");
		menu.setUrl("/userpage");
		menu.setId(1);
		menuList.add(menu);

		request.setAttribute("menulist", menuList);
    	request.setAttribute("username", "admin");
		/// request.setAttribute("tip", ((User) SecurityUtils.getSubject().getPrincipal()).getRoleTip());
		request.setAttribute("sex", "男");
		return "index1";

	}
	
}
